﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Classes="clr-namespace:SqliteHelper.Classes">

   <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="/SqliteHelper;component/Resources/Common.xaml" />
   </ResourceDictionary.MergedDictionaries>
    
   <DataTemplate DataType="{x:Type Classes:CopyTableViewModel}">
      <Grid>
         <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
         </Grid.RowDefinitions>
         
         <Grid Grid.Row="0">
            <Grid.RowDefinitions>
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="*" />
               <ColumnDefinition Width="Auto" />
               <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            
            <TextBlock Text="From"
                       HorizontalAlignment="Center"
                       Grid.Column="0"
                       Grid.Row="0" />

            <TextBlock Text="To"
                       Grid.Row="0"
                       Grid.Column="2"
                       HorizontalAlignment="Center" />

            <ComboBox Grid.Row="1"
                      Grid.Column="0"
                      DisplayMemberPath="FileName"
                      SelectedItem="{Binding Path=DatabaseFrom}"
                      ItemsSource="{Binding Path=Parent.DatabaseList}"/>

            <TextBlock Text="Database"
                       Grid.Row="1"
                       Grid.Column="1"
                       Margin="4"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center" />

            <ComboBox Grid.Row="1"
                      Grid.Column="2"
                      DisplayMemberPath="FileName"
                      SelectedItem="{Binding Path=DatabaseTo}"
                      ItemsSource="{Binding Path=Parent.DatabaseList}" />

            <ComboBox Grid.Row="2"
                      Grid.Column="0"
                      DisplayMemberPath="Text"
                      SelectedItem="{Binding Path=TableFrom}"
                      ItemsSource="{Binding Path=DatabaseFrom.TableList}" />

            <TextBlock Text="Table"
                       Grid.Row="2"
                       Grid.Column="1"
                       Margin="4"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center" />

            <ComboBox Grid.Row="2"
                      Grid.Column="2"
                      DisplayMemberPath="Text"
                      SelectedItem="{Binding Path=TableTo}"
                      ItemsSource="{Binding Path=DatabaseTo.TableList}" />

         </Grid>

         <Grid Grid.Row="1">
            <Grid.RowDefinitions>
               <RowDefinition Height="Auto" />
               <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Text="Mappings"
                       HorizontalAlignment="Center"
                       Grid.Row="0" />
            <ListBox Grid.Row="1"
                     ItemsSource="{Binding Path=FieldMappings}">
               <ListBox.ItemContainerStyle>
                  <Style TargetType="ListBoxItem">
                     <Setter Property="Template">
                        <Setter.Value>
                           <ControlTemplate>
                              <Grid>
                                 <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                 </Grid.ColumnDefinitions>
                                 <TextBlock Text="{Binding Path=From}"
                                            Grid.Column="0"/>
                                 <TextBlock Text=" - "
                                            Grid.Column="1"/>
                                 <TextBlock Text="{Binding Path=To}"
                                            Grid.Column="2"/>
                              </Grid>
                           </ControlTemplate>
                        </Setter.Value>
                     </Setter>
                  </Style>
               </ListBox.ItemContainerStyle>
            </ListBox>
         </Grid>
         
         <Grid Grid.Row="2"
               Margin="0,10,0,10">
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="*" />
               <ColumnDefinition Width="*" />
               <ColumnDefinition Width="Auto" />
               <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <ComboBox Grid.Column="0"
                      DisplayMemberPath="Text"
                      SelectedIndex="{Binding Path=FieldFromIndex, Mode=TwoWay}"
                      SelectedItem="{Binding Path=FieldFrom, Mode=TwoWay}"
                      ItemsSource="{Binding Path=TableFrom.Children}" />

            <ComboBox Grid.Column="1"
                      DisplayMemberPath="Text"
                      SelectedIndex="{Binding Path=FieldToIndex, Mode=TwoWay}"
                      SelectedItem="{Binding Path=FieldTo, Mode=TwoWay}"
                      ItemsSource="{Binding Path=TableTo.Children}" />

            <Button Grid.Column="2"
                    Margin="4,0,4,0"
                    Style="{StaticResource _ToolBarButton}"
                    Command="{Binding Path=AddMappingCommand}">
               <StackPanel Orientation="Horizontal">
                  <Image Source="/SqliteHelper;component/Images/add.png"
                         Width="16"
                         Height="16" />
                  <TextBlock Text="Add"
                             Margin="3,0,0,0" />
               </StackPanel>
            </Button>

            <Button Grid.Column="3"
                    Style="{StaticResource _ToolBarButton}"
                    Command="{Binding Path=DeleteMappingCommand}">
               <StackPanel Orientation="Horizontal">
                  <Image Source="/SqliteHelper;component/Images/cancel.png"
                         Width="16"
                         Height="16" />
                  <TextBlock Text="Delete"
                             Margin="3,0,0,0" />
               </StackPanel>
            </Button>
         </Grid>
         
         <Grid Grid.Row="3">
            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="Auto" />
               <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            
            <TextBlock Text="WHERE:"
                       Grid.Column="0"
                       VerticalAlignment="Center" />
            <TextBox Text="{Binding Path=WhereClause}"
                     Margin="4,0,0,0"
                     Grid.Column="1"/>
         </Grid>
      </Grid>
   </DataTemplate>
</ResourceDictionary>